home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / c / demos / bigmenu.c next >
C/C++ Source or Header  |  2000-02-28  |  3KB  |  124 lines

  1. //
  2. // $VER: BigMenu.c 1.6 (05.09.98)
  3. //
  4. // Popup Menu library test program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. // This little hack is intended to test the submenus.
  11. //
  12. // WARNING! When the menu runs out of stack, it will end in a crash!
  13. //
  14.  
  15. #include <intuition/intuition.h>
  16.  
  17. #include <proto/intuition.h>
  18. #include <proto/exec.h>
  19.  
  20. #include <clib/alib_protos.h>
  21.  
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. #include <libraries/pm.h>
  27. #include <proto/pm.h>
  28.  
  29. struct IntuitionBase    *IntuitionBase;
  30. struct GfxBase        *GfxBase;
  31. struct PopupMenuBase    *PopupMenuBase;
  32.  
  33. struct Window *w;    // This window is only needed to find out when and where the menu should appear and wich screen it's on.
  34.  
  35. void main()
  36. {
  37.     BOOL r=TRUE;
  38.     struct IntuiMessage *im,imsg;
  39.     struct PopupMenu *p;
  40.     struct PopupMenu *subs[20], *prev=0L;
  41.     int i;
  42.  
  43.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  44.     if(PopupMenuBase) {
  45.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  46.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  47.  
  48.         prev=PM_MakeMenu(
  49.             PMInfo("Congratulations!!"), End,
  50.             PMInfo("You've shown a great"), End,
  51.             PMInfo("deal of patience"), End,
  52.             PMInfo("working your way"), End,
  53.             PMInfo("through all theese"), End,
  54.             PMInfo("menus!"), End,
  55.             PMInfo("You will now be"), End,
  56.             PMInfo("rewarded with a"), End,
  57.             PMInfo("menu option that"), End,
  58.             PMInfo("lets you stop"), End,
  59.             PMInfo("browsing through"), End,
  60.             PMInfo("the menus..."), End,
  61.             PMBar, End,
  62.             PMItem("Quit"), PM_UserData, 5, End,
  63.         End;
  64.  
  65.         for(i=0;i<20;i++) {
  66.             char bfr[50];
  67.  
  68.             sprintf(bfr, "SubMenu #%ld", 20-i);
  69.  
  70.             prev=PM_MakeMenu(
  71.                 PMInfo(bfr), End,
  72.                 PMItem("Next Submenu"), PM_Sub, prev, End,
  73.             End;
  74.         }
  75.  
  76.         p=PMMenu("Big Menu"),    // Create a big menu...
  77.             PMInfo("Welcome to the neverending"), End,
  78.             PMInfo("submenu example."), End,
  79.             PMBar, End,
  80.             PMItem("Submenu"), PM_Sub, prev, End,
  81.             PMBar,    End,
  82.             PMItem("Quit"),    PM_UserData,    5,    End,
  83.             End;
  84.  
  85.         if(p) {
  86.  
  87.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  88.                     WA_RMBTrap,    TRUE,
  89.                     WA_DragBar,    TRUE,
  90.                     WA_Width,    150,
  91.                     WA_Height,    100,
  92.                     WA_Left,    150,
  93.                     WA_Top,        0,
  94.                     WA_Title,    "BigMenu",
  95.                     WA_CloseGadget,    TRUE,
  96.                     TAG_DONE);
  97.             if(w) {
  98.                 while(r) {
  99.                     WaitPort(w->UserPort);                        // Wait for a message
  100.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  101.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  102.                         ReplyMsg((struct Message *)im);                // Reply the message
  103.  
  104.                         switch(imsg.Class) {
  105.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  106.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  107.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  108.                                         PM_Menu,        p,
  109.                                         PM_Code,        imsg.Code,    // Must always be there!
  110.                                         TAG_DONE))-5);
  111.                             break;
  112.                         }
  113.                     }
  114.                 }
  115.                 CloseWindow(w);
  116.             } else printf("Window error!\n");
  117.  
  118.             PM_FreePopupMenu(p);
  119.  
  120.         } else printf("Menu error!\n");
  121.         CloseLibrary((struct Library *)PopupMenuBase);
  122.     }
  123. }
  124.